<?php

namespace Juheip\IpService\factory;

use Juheip\IpService\contract\PlatformInterface;
use Juheip\IpService\platforms\jialai\JiaLaiPlatform;
use Juheip\IpService\platforms\jingyun\JingYunPlatform;
use Juheip\IpService\platforms\jinyou\JinYouPlatform;
use Juheip\IpService\platforms\tianxing\TianXingPlatform;

class PlatformFactory
{
    public static function make(string $platform, array $config): PlatformInterface
    {
        $platformMap = [
            'jinyou' => JinYouPlatform::class,
            'jialai' => JiaLaiPlatform::class,
            'tianxing' => TianXingPlatform::class,
            'jingyun' => JingYunPlatform::class
        ];
        
        if (!isset($platformMap [$platform])) {
            throw new \Exception("不支持的平台：" . $platform);
        }

        $platformClass = $platformMap [$platform];

        return (new $platformClass())->init($config);
    }
}